package com.xy.mvvmdemo

import android.content.pm.PackageManager
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.Handler
import android.os.Message

import androidx.navigation.Navigation

import com.ashokvarma.bottomnavigation.BottomNavigationBar
import com.ashokvarma.bottomnavigation.BottomNavigationItem

import kotlinx.android.synthetic.main.activity_main.*


const val Msg = "msg"
class MainActivity : AppCompatActivity() {
    var handler = object : Handler() {
        override fun handleMessage(msg: Message) {
            when(msg.what){
                1->{}
                2->{}
            }
        }
    }
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        var str = "测试"

//        getChannel() //获取清单文件里metadata数据

        bottomBar.setMode(BottomNavigationBar.MODE_FIXED)
            .setBackgroundStyle(BottomNavigationBar.BACKGROUND_STYLE_DEFAULT)
            .setBarBackgroundColor("#ffffff")
            .setInActiveColor("#999999")
            .setActiveColor("#222222")
        bottomBar.addItem(BottomNavigationItem(R.mipmap.main_index_select_icon,"One").setInactiveIconResource(R.mipmap.main_index_icon))
            .addItem(BottomNavigationItem(R.mipmap.main_index_select_icon,"Two").setInactiveIconResource(R.mipmap.main_index_icon))
            .addItem(BottomNavigationItem(R.mipmap.main_index_select_icon,"Three").setInactiveIconResource(R.mipmap.main_index_icon))
            .addItem(BottomNavigationItem(R.mipmap.main_index_select_icon,"Four").setInactiveIconResource(R.mipmap.main_index_icon))
            .addItem(BottomNavigationItem(R.mipmap.main_index_select_icon,"Five").setInactiveIconResource(R.mipmap.main_index_icon))
            .initialise()
//        var fragmentAdapter = MyFragmentAdapter(supportFragmentManager,mutableListOf<Fragment>(newIntance(1),newIntance(2),newIntance(3),newIntance(4),newIntance(5)))
//        viewPage.adapter = fragmentAdapter
//        viewPage.currentItem = 0
        bottomBar.setTabSelectedListener(object :BottomNavigationBar.OnTabSelectedListener{
            override fun onTabSelected(position: Int) {
//                viewPage.currentItem = position
                when(position){
                    0->Navigation.findNavController(this@MainActivity,R.id.main).navigate(R.id.myFragment)
                    1->{
                        var bundle = Bundle()
                        bundle.putString(Msg,"主界面发送的消息")
                        Navigation.findNavController(this@MainActivity,R.id.main).navigate(R.id.oneFragment,bundle)
                    }
                    2->Navigation.findNavController(this@MainActivity,R.id.main).navigate(R.id.twoFragment)
                    3->Navigation.findNavController(this@MainActivity,R.id.main).navigate(R.id.threeFragment)
                    4->Navigation.findNavController(this@MainActivity,R.id.main).navigate(R.id.fourFragment)
                }
            }

            override fun onTabUnselected(position: Int) {

            }

            override fun onTabReselected(position: Int) {

            }

        })
//        viewPage.setOnPageChangeListener(object :ViewPager.OnPageChangeListener{
//            override fun onPageScrolled(
//                position: Int,
//                positionOffset: Float,
//                positionOffsetPixels: Int
//            ) {
//
//            }
//
//            override fun onPageSelected(position: Int) {
//                bottomBar.selectTab(position)
//            }
//
//            override fun onPageScrollStateChanged(state: Int) {
//
//            }
//
//        })
    }


//    private fun getChannel(){
//        try {
//            val applicationInfo =
//                packageManager.getApplicationInfo(packageName, PackageManager.GET_META_DATA)
//            val get = applicationInfo.metaData.get("CHANNEL_VALUE")
//        }catch (e:PackageManager.NameNotFoundException){
//            e.printStackTrace()
//        }
//
//
//    }

}